<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

class AutogeneratorViewXml_elements extends JViewLegacy
{
    public $oApplication;
    
	protected $items;
    
	protected $pagination;

	protected $state;
    
    public $iXmlTypeId;

	public function display($tpl = null)
	{
        $this->oApplication = JFactory::getApplication();
        $this->iXmlTypeId = $this->oApplication->input->getInt('iXmlTypeId');
        if ($this->iXmlTypeId < 1)
        {
            $sLink = JRoute::_('index.php?option=com_autogenerator&view=xml_types', false);
            
            $this->oApplication->redirect($sLink, JText::_('COM_AUTOGENERATOR_XML_ELEMENTS_XML_TYPE_ID_IS_NOT_VALID'), 'error');
        }
        
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');
		$this->state		= $this->get('State');
		
		$this->addToolbar();
		
		$this->addFilter();
		
		parent::display($tpl);
	}
	
	protected function addToolbar()
	{
		JToolbarHelper::title(JText::_('COM_AUTOGENERATOR_XML_ELEMENTS_TITLE'));
		
		JToolbarHelper::addNew('xml_element.add');
        
        JToolbarHelper::deleteList(JText::_('COM_AUTOGENERATOR_MESSAGE_CONFIRM_DELETE'), 'xml_elements.delete', 'JTOOLBAR_DELETE');
		
		JToolbarHelper::cancel('xml_element.cancel');
	}
	
	protected function addFilter()
	{
		JHtmlSidebar::setAction('index.php?option=com_autogenerator&view=xml_elements');
		
		$this->sidebar = JHtmlSidebar::render();
	}
	
	protected function getSortFields()
	{
		return array('axe.id' => JText::_('JGRID_HEADING_ID'));
	}
}
